﻿using System;
using CCWP7.Model;
using System.Diagnostics;
using Caliburn.Micro;

namespace CCWP7.CaliburnMicro
{
    public class ServersViewModel : Conductor<Server>.Collection.OneActive
    {
        readonly INavigationService _navigationService;
        readonly IServerDataManager _serverDataManager;

        public ServersViewModel(INavigationService navigationService, IServerDataManager serverDataManager)
        {
            Debug.Assert(navigationService != null, "navigationService is null.");
            Debug.Assert(serverDataManager != null, "serverDataManager is null.");

            _navigationService = navigationService;
            _serverDataManager = serverDataManager;

            Items.AddRange(serverDataManager.Servers);
        }

        public override void ActivateItem(Server server)
        {
            base.ActivateItem(server);
            if (server != null)
                _navigationService.Navigate(new Uri("/ServerPage.xaml?Id=" + server.SafeGetId(), UriKind.Relative));
        }
    }
}
